/**
 * 项目名：化工企业安全生产信息化管理平台
 * 日期：    2020-03-25 21:12:01
 * Copyright (c) 2015- -版权所有
 */

package com.joysuch.wwyt.bp.controller;

import javax.validation.Valid;

import cn.zlg.common.springmvc.validate.constraints.NotNull;
import com.joysuch.wwyt.bp.bean.BpIndustrialInjureApplyEditBean;
import com.joysuch.wwyt.bp.bean.BpIndustrialInjureApplyListBean;
import com.joysuch.wwyt.bp.bean.BpIndustrialInjureApplyListBean.SearchBpIndustrialInjureApply;
import com.joysuch.wwyt.bp.service.BpIndustrialInjureApplyService;
import com.joysuch.wwyt.core.common.ajax.ResultBean;
import com.joysuch.wwyt.core.common.util.PageDataUtils;
import io.swagger.annotations.Api;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Api(tags = "事故申报")
@RequestMapping("/bp/industrial-injure-apply")
public class BpIndustrialInjureApplyController {

    private static final Logger logger = LoggerFactory.getLogger(BpIndustrialInjureApplyController.class);

    @Autowired
    private BpIndustrialInjureApplyService bpIndustrialInjureApplyService;

    @RequiresPermissions("bp:industrial:injure:apply:add")
    @RequestMapping("add")
    public Object add(@Valid @RequestBody BpIndustrialInjureApplyEditBean entity) {
        bpIndustrialInjureApplyService.add(entity);
        return ResultBean.success("");
    }

    @RequiresPermissions("bp:industrial:injure:apply:update")
    @RequestMapping("update")
    public Object update(@Valid @RequestBody BpIndustrialInjureApplyEditBean entity) {
        if (entity.getId() == null) {
            return ResultBean.fail(102, "未指定主键");
        }
        bpIndustrialInjureApplyService.update(entity);
        return ResultBean.success("");
    }

    @RequiresPermissions("bp:industrial:injure:apply")
    @RequestMapping("page")
    public Object page(Pageable page, SearchBpIndustrialInjureApply condition) {
        page = PageDataUtils.addOrderByDesc(page, "id");
        Page<BpIndustrialInjureApplyListBean> data = bpIndustrialInjureApplyService.findByPage(page, condition);
        return ResultBean.pageData(data.getContent(), data.getTotalElements());
    }

    @RequiresPermissions("bp:industrial:injure:apply")
    @RequestMapping("select-page")
    public Object selectPage(Pageable page, SearchBpIndustrialInjureApply condition) {
        page = PageDataUtils.addOrderByDesc(page, "id");
        Page<BpIndustrialInjureApplyListBean> data = bpIndustrialInjureApplyService.findByPage(page, condition);
        return ResultBean.pageData(data.getContent(), data.getTotalElements());
    }

    @RequiresPermissions("bp:industrial:injure:apply:delete")
    @RequestMapping("delete")
    public Object delete(Long id) throws Exception {
        bpIndustrialInjureApplyService.delete(id);
        return ResultBean.success("");
    }

    @RequiresPermissions("bp:industrial:injure:apply")
    @RequestMapping("get")
    public Object getById(Long id) {
        return ResultBean.success(bpIndustrialInjureApplyService.getById(id));
    }
}
